sprite = codesters.Sprite("knight1", -175, -150)
sprite.set_speed(2)
def park_scene():
stage.set_background("park")
sprite.say("I should hurry to the castle!")
sprite.move_forward(550)
park_scene()
def bridge_scene():
stage.set_background("drawbridge")
sprite.go_to(-175, -150)
sprite.say("I made it!")
stage.wait(2)
bridge_scene()
def battle_scene():
dragon = codesters.Sprite("dragon", 150, -150)
sprite.say("Oh no a dragon!")
sprite.move_forward(300)
dragon.turn_left(360)
dragon.move_down(200)
sprite.say("The path is clear!")
battle_scene()
def reward_scene():
stage.set_background("castle")
wizard = codesters.Sprite("wizard", -150, -150)
wizard.say("You defeated the dragon!")
stage.wait(2)
t = codesters.Teacher()
try:
wizard_say = t.find_text('wizard.say')
tval1 = wizard_say[1][0]
tval1a = t.get_indent_at_line(tval1)
tval2 = wizard_say[1][1].lower()
except:
tval1 = "DNE"
tval1a = "DNE"
tval2 = "DNE"
try:
wait_param = t.find_function('wait')
tval3 = wait_param[2][1]
tval3a = wait_param[2][0]
except:
tval3 = "DNE"
tval3a = "DNE"
try:
tr_param = t.find_function('Sprite')
tval4 = tr_param[3][1]
tval4a = t.get_indent_at_line(tr_param[3][0])
except:
tval4 = "DNE"
tval4a = "DNE"
# try:
# say_param = t.find_
t1 = TestObjective()
t1.add_success('reward' in tval2 and tval1a == 4, "Great job!")
t1.add_failure(tval2 == "DNE", "Did you add a Say command to your reward_scene function?")
t1.add_failure('am a sprite' in tval2, "Did you change the string in the Say command?")
t1.add_failure('reward' not in tval2, "Did you put a Say command in your reward_scene function to present the reward?")
t1.add_failure(tval1a < 4, "Make sure your Say command is indented inside your reward_scene function.")
t3 = TestObjective()
t3.add_success('treasurechest' in tval4 and tval4a == 4, "Great job!")
t3.add_failure(tval4a == 0, "Did you indent the treasure chest sprite 4 spaces inside the reward_scene function?")
t3.add_failure('sprite =' in tval4, "Did you change the name of the treasure chest sprite to treasure?")
t3.add_failure(tval4 == "DNE", "Did you add a treasure chest sprite to your reward_scene function?")
tester = TestManager()
tester.add_test_list([t1, t3])
tester.run_tests()
tester.display_first_feedback()
-
Run Code
-
Activity Submitted!
提交作品
-
下个活动
-
Stop Running Code
-
Show Chart
-
Show Console
-
Reset Code Editor
-
Codesters How To (opens in a new tab)